import simplejson as json

from redhat.configure_repositories import ConfigureRepositories
from redhat.configure_groups       import ConfigureGroups
from redhat.configure_users        import ConfigureUsers
from redhat.configure_packages     import ConfigurePackages
from redhat.configure_files        import ConfigureFiles
from redhat.configure_mounts       import ConfigureMounts
from redhat.configure_services     import ConfigureServices

#=======================================================

class Configure:
    def __init__(self, data):
        self.data     = json.JSONDecoder().decode(data)
        self.repos    = self.data['repositories']
        self.groups   = self.data['groups']
        self.users    = self.data['users']
        self.pkgs     = self.data['packages']
        self.files    = self.data['files']
        self.mounts   = self.data['mounts']
        self.services = self.data['services']

    def configure_repositories(self):
        repos = ConfigureRepositories(self.repos)
        stats = repos.configure()
        return stats
    def configure_groups(self):
        groups = ConfigureGroups(self.groups)
        stats = groups.configure()
        return stats
    def configure_users(self):
        users = ConfigureUsers(self.users)
        stats = users.configure()
        return stats
    def configure_packages(self):
        packages = ConfigurePackages(self.pkgs)
        stats = packages.configure()
        return stats
    def configure_files(self):
        files = ConfigureFiles(self.files)
        stats = files.configure()
        return stats
    def configure_mounts(self):
        mounts = ConfigureMounts(self.mounts)
        stats = mounts.configure()
        return stats
    def configure_services(self,service_list):
        services = ConfigureServices(self.services)
        stats = services.configure()
        services.restart(service_list)
        return stats
